<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.29
     from type.tnf on 19 December 2010 -->

<TITLE>Type Analysis - Typed Entities</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#FF0000" BACKGROUND="gifs/bg.gif">
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0" VALIGN=BOTTOM>
<TR VALIGN=BOTTOM>
<TD WIDTH="160" VALIGN=BOTTOM>
<A HREF="http://eli-project.sourceforge.net/">
<IMG SRC="gifs/elilogo.gif" BORDER=0>
</A>&nbsp;
</TD>
<TD WIDTH="25" VALIGN=BOTTOM>
<img src="gifs/empty.gif" WIDTH=25 HEIGHT=25>
</TD>
<TD ALIGN=LEFT WIDTH="475" VALIGN=BOTTOM>
<A HREF="index.html"><IMG SRC="gifs/title.png" BORDER=0></A>
</TD>
<!-- |DELETE FOR SOURCEFORGE LOGO|
<TD>
<a href="http://sourceforge.net/projects/eli-project">
<img
  src="http://sflogo.sourceforge.net/sflogo.php?group_id=70447&amp;type=13"
  width="120" height="30"
  alt="Get Eli: Translator Construction Made Easy at SourceForge.net.
    Fast, secure and Free Open Source software downloads"/>
</a>
</TD>
|DELETE FOR SOURCEFORGE LOGO| -->
</TR>
</TABLE>

<HR size=1 noshade width=785 align=left>
<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=0>
<TR>
<TD VALIGN=TOP WIDTH="160">
<h4>General Information</h4>

<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="index.html">Eli: Translator Construction Made Easy</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="gindex_1.html#SEC1">Global Index</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="faq_toc.html" >Frequently Asked Questions</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="ee.html" >Typical Eli Usage Errors</a> </td></tr>
</table>

<h4>Tutorials</h4>

<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="EliRefCard_toc.html">Quick Reference Card</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="novice_toc.html">Guide For new Eli Users</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="news_toc.html">Release Notes of Eli</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="nametutorial_toc.html">Tutorial on Name Analysis</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="typetutorial_toc.html">Tutorial on Type Analysis</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="ee.html" >Typical Eli Usage Errors</a> </td></tr>
</table>

<h4>Reference Manuals</h4>

<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="ui_toc.html">User Interface</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="pp_toc.html">Eli products and parameters</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="lidoref_toc.html">LIDO Reference Manual</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="ee.html" >Typical Eli Usage Errors</a> </td></tr>
</table>

<h4>Libraries</h4>

<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="lib_toc.html">Eli library routines</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="modlib_toc.html">Specification Module Library</a></td></tr>
</table>

<h4>Translation Tasks</h4>

<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="lex_toc.html">Lexical analysis specification</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="syntax_toc.html">Syntactic Analysis Manual</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="comptrees_toc.html">Computation in Trees</a></td></tr>
</table>

<h4>Tools</h4>

<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="lcl_toc.html">LIGA Control Language</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="show_toc.html">Debugging Information for LIDO</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="gorto_toc.html">Graphical ORder TOol</a> </td></tr>
</table>
<p>
<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="fw_toc.html">FunnelWeb User's Manual</a> </td></tr>
</table>
<p>
<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="ptg_toc.html">Pattern-based Text Generator</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="deftbl_toc.html">Property Definition Language</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="oil_toc.html">Operator Identification Language</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="tp_toc.html">Tree Grammar Specification Language</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="clp_toc.html">Command Line Processing</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="cola_toc.html">COLA Options Reference Manual</a> </td></tr>
</table>
<p>
<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="idem_toc.html">Generating Unparsing Code</a> </td></tr>
</table>
<p>
<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="mon_toc.html">Monitoring a Processor's Execution</a> </td></tr>
</table>

<h4>Administration</h4>

<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="sysadmin_toc.html">System Administration Guide</a> </td></tr>
</table>

<HR WIDTH="100%">
<A HREF="mailto:eli-project-users@lists.sourceforge.net">
<IMG SRC="gifs/button_mail.gif" BORDER=0 ALIGN="left"></A>
<A HREF="index.html"><IMG SRC="gifs/home.gif" BORDER=0 ALIGN="right"></A>

</TD>
<TD VALIGN=TOP WIDTH="25"><img src="gifs/empty.gif" WIDTH=25 HEIGHT=25></TD>

<TD VALIGN=TOP WIDTH="600">
<H1>Type Analysis</H1>
<P>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT=""><A HREF="type_2.html"><IMG SRC="gifs/prev.gif" ALT="Previous Chapter" BORDER="0"></A>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT=""><A HREF="type_4.html"><IMG SRC="gifs/next.gif" ALT="Next Chapter" BORDER="0"></A>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT=""><A HREF="type_toc.html"><IMG SRC="gifs/up.gif" ALT="Table of Contents" BORDER="0"></A>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT="">
<HR size=1 noshade width=600 align=left>
<A NAME="IDX10"></A>
<A NAME="IDX11"></A>
<A NAME="IDX12"></A>
<H1><A NAME="SEC8" HREF="type_toc.html#SEC8">Typed Entities</A></H1>
<P>
A <EM>typed entity</EM> is a named program component, one of whose properties
is a type.
Variables, formal parameters, and fields are the most common typed
entities; functions are also typed entities in some languages
(see  <A HREF="type_6.html#SEC28">Functions as typed entities</A>).
When an identifier is used to represent a typed entity,
the type specified by a defining occurrence of that identifier
must be made available at each applied occurrence.
This is accomplished through the use of a <CODE>DefTableKey</CODE>-valued
property of the definition table key characterizing the typed entity.
<P>
The <CODE>Typing</CODE> module exports computational roles to
implement the definition and use of typed entities:
<P>
<A NAME="IDX13"></A>
<DL COMPACT>
<DT><CODE>TypedDefinition</CODE>
<DD>The computational role inherited by a grammar symbol that represents
a definition of one or more typed entities having the same type.
<A NAME="IDX14"></A>
<P>
<DT><CODE>TypedDefId</CODE>
<DD>The computational role inherited by a grammar symbol that represents
a defining occurrence of an identifier for a typed entity.
<A NAME="IDX15"></A>
<P>
<DT><CODE>TypedUseId</CODE>
<DD>The computational role inherited by a grammar symbol that represents
an applied occurrence of an identifier for a typed entity.
</DL>
<P>
The <CODE>Typing</CODE> module is instantiated by
<P>
<PRE>
   $/Type/Typing.gnrc +referto=<SAMP>`prefix'</SAMP> :inst
</PRE>
<CODE><SAMP>`prefix'</SAMP>Key</CODE> (or simply <CODE>Key</CODE> if the <CODE>referto</CODE>
parameter is mising) must be the name of an attribute of every
grammar symbol inheriting the <CODE>TypedDefId</CODE> or <CODE>TypedUseId</CODE> role.
The value of that attribute must be the definition table key bound to the
symbol during name analysis
(see  <A HREF="name_toc.html">Name analysis according to scope rules of Specification Module Library</A>).
<P>
<H2><A NAME="SEC9" HREF="type_toc.html#SEC9">Establishing the type of an entity</A></H2>
<P>
A typical local variable declaration from Java or C specifies a type and a
list of variable names:
<P>
<PRE>
int a, b, c;
</PRE>
The entire declaration plays the role of a <CODE>TypedDefinition</CODE>;
each of <CODE>a</CODE>, <CODE>b</CODE>, and <CODE>c</CODE> plays the role of a
<CODE>TypedDefId</CODE>.
<P>
The value of the <CODE>TypedDefinition.Type</CODE> attribute must be set
by a user computation to the definition table key of the type.
No other user computations are needed because
default computations provided by the <CODE>Typing</CODE> module in descendent
<CODE>TypedDefId</CODE> constructs will access the <CODE>TypedDefinition.Type</CODE>
attribute, setting the appropriate property of the definition table key
characterizing the typed entity.
<P>
A Java or C compiler might use the following specification to describe a
variable declaration:
<P>
<A NAME="IDX16"></A>
<A NAME="IDX17"></A>
<PRE>
SYMBOL VrblDecl INHERITS TypedDefinition END;
SYMBOL VarIdDef INHERITS TypedDefId      END;

RULE: VrblDecl ::= Type VarIdDefs ';' COMPUTE
  VrblDecl.Type=Type.Type;
END;

RULE: VarIdDefs LISTOF VarIdDef END;
</PRE>
<P>
<H2><A NAME="SEC10" HREF="type_toc.html#SEC10">Accessing the type of an entity</A></H2>
<P>
<CODE>TypedUseId</CODE>
is an applied occurrence of an identifier representing a typed entity.
A <CODE>Typing</CODE> module computation sets the value of the <CODE>TypedUseId.Type</CODE>
attribute to the definition table key representing the entity's type.
<P>
If <CODE>ExpIdUse</CODE> represented an applied occurrence of a variable or
parameter identifier in the abstract syntax tree, the <CODE>Typing</CODE> module
will provide a value for <CODE>ExpIdUse.Type</CODE> if the following line
appears in the specification:
<P>
<A NAME="IDX18"></A>
<PRE>
SYMBOL ExpIdUse INHERITS TypedUseId END;
</PRE>
<P>
<H2><A NAME="SEC11" HREF="type_toc.html#SEC11">Passing ancillary information</A></H2>
<P>
The <CODE>Typing</CODE> module guarantees that every <CODE>TypedUseId.Type</CODE>
attribute depends on all of the type analysis computations
(see  <A HREF="type_8.html#SEC38">Dependences for typed entities</A>).
In other words, any computation accessing <CODE>TypedUseId.Type</CODE> is
guaranteed to take place after all type analysis computations have been
completed.
This dependence can be used to guarantee the availability of information
characterizing the typed entity that is ancillary to type analysis.
<P>
The operation that sets the <CODE>Type</CODE> property of the definition table key
characterizing the typed entity depends on the void attribute 
<CODE>TypedDefId.GotProp</CODE>.
<CODE>TypedDefId.GotProp</CODE> is set by a default symbol computation that can
be overridden by an upper-context computation of the symbol inheriting
<CODE>TypedDefId</CODE> or by a computation in a rule having the symbol
inheriting <CODE>TypedDefId</CODE> on the right-hand side.
The <CODE>Typing</CODE> module will then guarantee that such a computation has
been carried out before any access to <CODE>TypedUseId.Type</CODE> is allowed.
Any such computation must, however, be independent of all results of type
analysis.
<P>
Pascal's distinction between variable and value parameters is a typical
example of information ancillary to type analysis that must be conveyed
from defining to applied occurences of typed entities:
<P>
<A NAME="IDX19"></A>
<A NAME="IDX20"></A>
<A NAME="IDX21"></A>
<PRE>
ATTR IsVarParam: int;

SYMBOL FormalParamSect INHERITS TypedDefinition COMPUTE
  SYNT.IsVarParam=0;
END;

RULE: FormalParamSect ::= 'var' Formals ':' Type COMPUTE
  FormalParamSect.IsVarParam=1;
END;

SYMBOL FormalIdDef INHERITS TypedIdDef COMPUTE
  INH.GotProp=
    ResetIsVarParam(THIS.Key,INCLUDING FormalParamSect.IsVarParam);
END;

SYMBOL ExpIdUse INHERITS TypedUseId COMPUTE
  SYNT.IsVarParam=GetIsVarParam(THIS.Key,0) &#60;- THIS.Type;
END;
</PRE>
This computation assumes that an integer-valued property <CODE>IsVarParam</CODE>
has been defined.
It is set by a computation in the upper context of <CODE>FormalIdDef</CODE> that
overrides the default computation of the void attribute
<CODE>TypedIdDef.GotProp</CODE>, and queried by a symbol computation in the lower
context of <CODE>ExpIdUse</CODE>.
The latter computation depends on <CODE>ExpIdUse.Type</CODE>, so the
<CODE>Typing</CODE> module guarantees that the property value has been set for
every formal parameter before it is queried.
<P>
<CODE>FormalParamSect.IsVarParam</CODE> is an integer valued attribute, distinct
from the <CODE>IsVarParam</CODE> property, set by a symbol computation in the
lower context of <CODE>FormalParamSect</CODE>.
That symbol computation is overridden in the rule representing
a declaration of a variable parameter.
<P>
Note that a particular instance of symbol <CODE>ExpIdUse</CODE> in the tree does
not necessarily represent an applied occurrence of a formal parameter.
(It might represent an applied occurrence of a variable identifier, for
example.)
Thus the <CODE>IsVarParam</CODE> property might not be set; the query will return
the default value 0 in that case.
The overall effect of these computations is therefore to set the value of
<CODE>ExpIdUse.IsVarParam</CODE> to 1 if and only if that instance of
<CODE>ExpIdUse</CODE> represents an applied occurrence of a variable parameter.
<P>
<HR size=1 noshade width=600 align=left>
<P>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT=""><A HREF="type_2.html"><IMG SRC="gifs/prev.gif" ALT="Previous Chapter" BORDER="0"></A>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT=""><A HREF="type_4.html"><IMG SRC="gifs/next.gif" ALT="Next Chapter" BORDER="0"></A>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT=""><A HREF="type_toc.html"><IMG SRC="gifs/up.gif" ALT="Table of Contents" BORDER="0"></A>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT="">
<HR size=1 noshade width=600 align=left>
</TD>
</TR>
</TABLE>

</BODY></HTML>
